package cn.italkcloud.cph.constants.enums.vos;

import lombok.Getter;

import java.util.Objects;

/**
 * 0 普通账户 1 电话卡 2结算账户
 *
 * @author dominate
 * @since 2024/7/9
 **/
@Getter
public enum CustomerTypeEnum {
    ALL(-1, "全部"),
    GENERAL(0, "普通账户"),
    PHONE(1, "电话卡"),
    SETTLEMENT(2, "结算账户");

    final int code;
    final String name;

    CustomerTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static CustomerTypeEnum getValueByCode(Integer code) {
        if (Objects.isNull(code)) {
            return GENERAL;
        }
        for (CustomerTypeEnum value : CustomerTypeEnum.values()) {
            if (code == value.getCode()) {
                return value;
            }
        }
        return GENERAL;
    }

    public static String getName(int code) {
        return getValueByCode(code).getName();
    }
}
